package com.yiwenup.leetcode.top_interview_150;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * 文件描述
 *
 * @Project struct-algorithm
 * @Package com.yiwenup.leetcode.top_interview_150
 * @Author yiwenup
 * @Date 2024-12-19 21:21:04
 * @Description https://leetcode.cn/problems/isomorphic-strings/?envType=study-plan-v2&envId=top-interview-150
 */
public class No0205 {
    public boolean isIsomorphic(String s, String t) {
        Map<Character, Character> tmp1 = new HashMap<>();
        Map<Character, Character> tmp2 = new HashMap<>();
        for (int i = 0; i < s.length(); i++) {
            char sc = s.charAt(i);
            char tc = t.charAt(i);
            if ((tmp1.containsKey(sc) && tmp1.get(sc) != tc) || (tmp2.containsKey(tc) && tmp2.get(tc) != sc)) {
                return false;
            }
            tmp1.put(sc, tc);
            tmp2.put(tc, sc);
        }
        return true;
    }

    public static void main(String[] args) {
        System.out.println(new No0205().isIsomorphic("egg", "add"));
    }
}
